set.seed(100)

ind <- sample(2, nrow(iris), replace = TRUE, prob = c(0.7, 0.3))
train <- iris[ind==1, ]
test <- iris[ind==2, ]

library(party)

flower_model <- Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width

iris_tree <- ctree(flower_model, data = train)

table(predict(iris_tree), train$Species)

print(iris_tree)
plot(iris_tree)
plot(iris_tree, type = "simple")


testPredict <- predict(iris_tree, newdata = test)
table(testPredict, test$Species)


# ----

library(RWeka)

c45_iris_tree <-
  J48(flower_model, data = train, control = Weka_control(U = TRUE))

c45_iris_tree

summary(c45_iris_tree)

plot(c45_iris_tree)


c45_testPredict <- predict(c45_iris_tree, newdata = test)
table(c45_testPredict, test$Species)

